{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Infrastructure" %}{% endblock %}
{% block content %}
    <div class="row">
        <div class="col-xs-12" role="main">
            <div class="page-header page-header__filter clearfix">
                <h1>{% trans "Infrastructure" %}</h1>
                <div class="input-append form-inline">
                    <div class="form-group">
                        <input type="text" class="form-control" id="filter_input">
                    </div>
                    <div class="form-group">
                        <input type="button" class="btn btn-default" id="filter_button" value="Filter">
                        <button type="button" class="btn btn-default" id="filter_clear">Clear</button>
                    </div>
                </div>
            </div>
            {% if hosts_vms %}
                <div id="hide_vms_bystate" class="text-right">
                    <div class="form-group">
                        <span>Hide:</span>
                        <label class="text-success">
                            <input type="checkbox" data-value="1"> {% trans "Running" %}</input>
                        </label>
                        <label class="text-warning">
                            <input type="checkbox" data-value="3"> {% trans "Suspend" %}</input>
                        </label>
                        <label class="text-danger">
                            <input type="checkbox" data-value="5"> {% trans "Shutoff" %}</input>
                        </label>
                    </div>
                </div>
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th style="width: 10px;">#</th>
                            <th>{% trans "Hostname / VMs" %}</th>
                            <th>{% trans "Status" %}</th>
                            <th style="text-align:center;width:50px;">{% trans "VCPUs" %}</th>
                            <th style="text-align:center;width:100px;">{% trans "Memory" %}</th>
                            <th style="text-align:center;width:80px;">{% trans "Usage" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for host, vms in hosts_vms.items %}
                            <tr style="font-size:18px;">
                                <td>{{ forloop.counter }}</td>
                                <td><a href="{% url 'instances' host.0 %}">{{ host.1 }}</a></td>
                                <td>{% ifequal host.2 1 %}<span class="label label-success">{% trans "Active" %}
                                    </span>{% endifequal %}
                                    {% ifequal host.2 2 %}<span class="label label-danger">{% trans "Not Active" %}
                                        </span>{% endifequal %}
                                    {% ifequal host.2 3 %}<span class="label label-danger">{% trans "Connection Failed" %}
                                        </span>{% endifequal %}
                                </td>
                                <td style="text-align:center;">{{ host.3 }}</td>
                                <td style="text-align:center;">{{ host.4|filesizeformat }}</td>
                                <td style="text-align:center;">{{ host.5 }}%</td>
                            </tr>
                            {% if vms %}
                                {% for vm, info in vms.items %}
                                    <tr data-status="{{ info.0 }}">
                                        <td></td>
                                        <td>{{ forloop.counter }} &emsp; <a
                                                href="{% url 'instance' host.0 vm %}">{{ vm }}</a></td>
                                        <td>{% ifequal info.0 1 %}<span class="label label-success">{% trans "Running" %}
                                            </span>{% endifequal %}
                                            {% ifequal info.0 3 %}<span class="label label-warning">{% trans "Suspend" %}
                                                </span>{% endifequal %}
                                            {% ifequal info.0 5 %}<span class="label label-danger">{% trans "Shutoff" %}
                                                </span>{% endifequal %}
                                        </td>
                                        <td style="text-align:center;">{{ info.1 }}</td>
                                        <td style="text-align:center;">{{ info.2|filesizeformat }}</td>
                                        <td style="text-align:center;">{{ info.3 }}%</td>
                                    </tr>
                                {% endfor %}
                            {% endif %}
                        {% endfor %}
                    </tbody>
                </table>
            {% else %}
                <div class="well">
                    <h4>{% trans "You have no connection" %}</h4>
                </div>
            {% endif %}
        </div>
    </div>
{% endblock %}
{% block script %}
    <script src="/static/js/infrastructure.js"></script>
{% endblock %}
